<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Zookeeper 架构设计核心组件</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .component-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            margin-bottom: 1rem;
        }
        .leader-icon { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
        .follower-icon { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
        .observer-icon { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); }
        .client-icon { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }
        .znode-icon { background: linear-gradient(135deg, #30cfd0 0%, #330867 100%); }
        .ensemble-icon { background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); }
        .log-icon { background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%); }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 1rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        
        .first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #667eea;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                <i class="fas fa-network-wired mr-4"></i>Zookeeper 架构设计
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">深入解析分布式协调服务的核心组件</p>
            <div class="flex justify-center space-x-8 text-sm">
                <div><i class="fas fa-server mr-2"></i>高可用性</div>
                <div><i class="fas fa-sync mr-2"></i>强一致性</div>
                <div><i class="fas fa-expand-arrows-alt mr-2"></i>易扩展</div>
            </div>
        </div>
    </div>

    <!-- Introduction -->
    <div class="container mx-auto px-6 py-12">
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="first-letter">Z</span>ookeeper 的架构设计通过这些核心组件相互配合，使其具备了高可用、高性能、强一致性和易扩展等特性，成为分布式系统中可靠的协调服务。每个组件在整个集群中扮演着特定的角色，确保了 Zookeeper 的稳定运行和高效运作。
            </p>
        </div>
    </div>

    <!-- Architecture Diagram -->
    <div class="container mx-auto px-6 py-8">
        <div class="bg-white rounded-2xl shadow-xl p-8">
            <h2 class="text-3xl font-bold text-center mb-8 text-gradient">架构关系图</h2>
            <div class="mermaid">
                graph TB
                    subgraph "Zookeeper Ensemble"
                        L[Leader<br/>领导者]
                        F1[Follower 1<br/>跟随者]
                        F2[Follower 2<br/>跟随者]
                        O1[Observer<br/>观察者]
                    end
                    
                    C1[Client 1<br/>客户端]
                    C2[Client 2<br/>客户端]
                    C3[Client 3<br/>客户端]
                    
                    Z[Znode Tree<br/>数据节点树]
                    LOG[Transaction Log<br/>事务日志]
                    SNAP[Snapshot<br/>快照]
                    
                    C1 -->|写请求| L
                    C2 -->|读请求| F1
                    C3 -->|读请求| O1
                    
                    L -->|同步| F1
                    L -->|同步| F2
                    L -->|同步| O1
                    
                    L --> Z
                    F1 --> Z
                    F2 --> Z
                    O1 --> Z
                    
                    L --> LOG
                    L --> SNAP
                    
                    style L fill:#f093fb,stroke:#f5576c,stroke-width:3px
                    style F1 fill:#4facfe,stroke:#00f2fe,stroke-width:2px
                    style F2 fill:#4facfe,stroke:#00f2fe,stroke-width:2px
                    style O1 fill:#43e97b,stroke:#38f9d7,stroke-width:2px
                    style C1 fill:#fa709a,stroke:#fee140,stroke-width:2px
                    style C2 fill:#fa709a,stroke:#fee140,stroke-width:2px
                    style C3 fill:#fa709a,stroke:#fee140,stroke-width:2px
            </div>
        </div>
    </div>

    <!-- Components Grid -->
    <div class="container mx-auto px-6 py-12">
        <h2 class="text-4xl font-bold text-center mb-12">
            <i class="fas fa-puzzle-piece mr-3 text-purple-600"></i>
            核心组件详解
        </h2>
        
        <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
            <!-- Leader -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="component-icon leader-icon">
                    <i class="fas fa-crown text-white text-2xl"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4">1. Leader（领导者）</h3>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold text-purple-600 mb-2"><i class="fas fa-bullseye mr-2"></i>作用</h4>
                        <p class="text-gray-700">在 Zookeeper 集群中，Leader 是唯一一个负责处理所有写请求的节点。所有的写操作都需要先发送到 Leader，Leader 会将这些操作按顺序应用到自身的内存状态中，并将操作的提案广播给所有的 Follower 节点。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-purple-600 mb-2"><i class="fas fa-cogs mr-2"></i>功能</h4>
                        <ul class="space-y-2 text-gray-700">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>处理客户端的写请求</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>发起并管理 ZAB 协议的各个阶段</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>确保集群内所有节点数据保持同步</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>负责协调集群内的节点状态，管理会话</li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Follower -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="component-icon follower-icon">
                    <i class="fas fa-users text-white text-2xl"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4">2. Follower（跟随者）</h3>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold text-blue-600 mb-2"><i class="fas fa-bullseye mr-2"></i>作用</h4>
                        <p class="text-gray-700">Follower 是 Zookeeper 集群中的从节点，主要用于处理读请求和同步 Leader 的状态。每个 Follower 从 Leader 那里接受提案，然后参与投票以达成一致性。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-blue-600 mb-2"><i class="fas fa-cogs mr-2"></i>功能</h4>
                        <ul class="space-y-2 text-gray-700">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>处理客户端的读请求，直接返回数据</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>接受并应用 Leader 发送的写提案</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>参与 Leader 选举过程</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>监控 Leader 的健康状态</li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Observer -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="component-icon observer-icon">
                    <i class="fas fa-eye text-white text-2xl"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4">3. Observer（观察者）</h3>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold text-green-600 mb-2"><i class="fas fa-bullseye mr-2"></i>作用</h4>
                        <p class="text-gray-700">Observer 是一种特殊类型的 Zookeeper 节点，它可以连接到集群中但不参与写请求的投票。主要目的是增加系统的读取扩展性，降低 Leader 的负载。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-green-600 mb-2"><i class="fas fa-cogs mr-2"></i>功能</h4>
                        <ul class="space-y-2 text-gray-700">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>处理客户端的读请求</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>参与集群状态更新但不参与投票</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>提升读性能，减轻集群压力</li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Client -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="component-icon client-icon">
                    <i class="fas fa-laptop-code text-white text-2xl"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4">4. Client（客户端）</h3>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold text-pink-600 mb-2"><i class="fas fa-bullseye mr-2"></i>作用</h4>
                        <p class="text-gray-700">Client 是使用 Zookeeper 服务的外部应用程序或服务，负责发起请求（读或写）到 Zookeeper 集群。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-pink-600 mb-2"><i class="fas fa-cogs mr-2"></i>功能</h4>
                        <ul class="space-y-2 text-gray-700">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>发送读请求和写请求到集群</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>管理与 Zookeeper 的会话</li>
                            <li><i class="fas